package com.ywl.designpattern.command;

public class CommandPatternDemo {

    public static void main(String[] args) {
        RemoteControl remote = new RemoteControl();

        Light livingRoomLight = new Light();
        TV livingRoomTv = new TV();

        LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
        LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
        TVOnCommand livingRooomTvOn = new TVOnCommand(livingRoomTv);
        TVOffCommand livingRoomTvOff = new TVOffCommand(livingRoomTv);

        remote.setCommand(0, livingRoomLightOn, livingRoomLightOff);
        remote.setCommand(1, livingRooomTvOn, livingRoomTvOff);

        // 打开电灯
        remote.onButtonWasPushed(0);
        // 关闭电灯
        remote.offButtonWasPushed(0);
        // 打开电视
        remote.onButtonWasPushed(1);
        // 关闭电视
        remote.offButtonWasPushed(1);
        // 撤销最后一个操作（打开电视）
        remote.undoButtonWasPushed();
    }
}
